#ifndef __UART2_H__
#define __UART2_H__
#include "stdio.h"	
#include "stm32f10x.h" 
#include "rtos.h"
#include "uartcommon.h"

#define UART2_TXBUFF_SIZE   1024
#define UART2_RXBUFF_SIZE   1024
#define UART2_RX_QUEUE_LEN  2
#define UART2_TX_INTERVAL 20    //ms
#define UART2_RX_INTERVAL 5  //ms



#ifndef TMDLY_BIT2
#define TMDLY_BIT2
#define UART2RXCTRBIT			0x004
#define UART2RXCTRTM			Timer3Ctr.time[2]
#define SETUART2RXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART2RXCTRBIT;\
														UART2RXCTRTM = (u32)UART2_RX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART2RXDLY()	{DISABLE_INT();\
														Timer3Ctr.devbit &= ~UART2RXCTRBIT;\
														UART2RXCTRTM = 0;\
														ENABLE_INT();}
#else
#error TMDLY_BIT2 has been defined!
#endif	//TMDLY_BIT2


#ifndef TMDLY_BIT3
#define TMDLY_BIT3
#define UART2TXCTRBIT			0x008
#define UART2TXCTRTM			Timer3Ctr.time[3]
#define SETUART2TXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART2TXCTRBIT;\
														UART2TXCTRTM = (u32)UART2_TX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART2TXDLY()	{DISABLE_INT();\
														Timer3Ctr.devbit &= ~UART2TXCTRBIT;\
														UART2TXCTRTM = 0;\
														ENABLE_INT();}
#else
#error TMDLY_BIT3 has been defined!
#endif	//TMDLY_BIT3




extern UARTSTRUCT MyUart2;
extern SemaphoreHandle_t  Binary_Uart2;
void Uart2_Init(u32 bound);






static void Uart2_TxDMAConfig(void);
static void Uart2TXDMAStart(u8 *senddata,u16 datalen);
static void Uart2_PutC(u8 udata);
static void Uart2_PutStrlen(u8 *senddata,u16 datalen);
static void Uart2_Printf(char* fmt,...) ;
static u8 Uart2_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart2_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart2_Var_Init(void);
static void Uart2_SendBeforCallBack(void);
static void Uart2_SendOverCallBack(void);
static void Uart2_StoreOneRxPkg(void);
static u8 Uart2_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart2_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart2_ReleaseAllRxPkg(void);
#endif


